package hos.http.converter;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * <p>Title: HttpConvertString </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023/4/4 18:06
 */
public abstract class HttpStringJsonConvert extends HttpStringConvert {

    protected final String success;
    protected final String code;
    protected final String message;

    public HttpStringJsonConvert(String success, String code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public HttpStringJsonConvert(String success, String code) {
        this(success, code, "msg");
    }

    public HttpStringJsonConvert() {
        this("200", "code", "msg");
    }

    @Override
    public <D> D parseJson(Type succeed, String json) throws IOException {
        String requireJson = HttpConverterUtils.requireJson(json, json, success, code, message);
        return parseBody(succeed, requireJson);
    }

    public abstract <D> D parseBody(Type succeed, String json) throws IOException;
}
